package pedongi.mobile.colorfinder.helper;

import java.util.ArrayList;

import android.util.Log;

import pedongi.mobile.colorfinder.knowledgebase.KnowledgeBaseDriver;
import pedongi.mobile.colorfinder.knowledgebase.QuestionSet;

public class Interviewer {
	private static Interviewer instance = null;
	private ArrayList<QuestionSet> questionSets;
	private ArrayList<Integer> answerSet;
	public ArrayList<Integer> getAnswerSet() {
		return answerSet;
	}

	private int currentQuestion = 0;
	
	private Interviewer() {
		questionSets = new ArrayList<QuestionSet>();
		
		initQuestionSet();
	}
	
	public void initialize() {
		currentQuestion = 0;		
		answerSet = new ArrayList<Integer>(17);
		for(int i=0; i<17; ++i) //Initialize all answer to be -1
			answerSet.add(new Integer(-1));
	}
	
	private void initQuestionSet() {
		ArrayList<String> options;
		
		///Q0
		options = new ArrayList<String>();
		options.add("Pastel");
		options.add("Gelap");
		options.add("Cerah");
		questionSets.add(new QuestionSet("Jenis warna yang disukai" , "jenis warna" , options));
		
		///Q1
		options = new ArrayList<String>();
		options.add("Minimalis");
		options.add("Modern");
		questionSets.add(new QuestionSet("Gaya ruangan yang diinginkan" , "gaya ruangan" , options));
		
		///Q2
		options = new ArrayList<String>();
		options.add("Kurang dari 3 meter");
		options.add("3-5 meter");
		options.add("Lebih dari 5 meter");
		questionSets.add(new QuestionSet("Ukuran panjang ruangan" , "panjang" , options));
		
		///Q3
		options = new ArrayList<String>();
		options.add("Kurang dari 3 meter");
		options.add("3-5 meter");
		options.add("Lebih dari 5 meter");
		questionSets.add(new QuestionSet("Ukuran lebar ruangan" , "lebar" , options));
		
		///Q4
		options = new ArrayList<String>();
		options.add("Kurang dari 3 meter");
		options.add("3-5 meter");
		options.add("Lebih dari 5 meter");
		questionSets.add(new QuestionSet("Ukuran tinggi ruangan" , "tinggi" , options));
		
		///Q5
		options = new ArrayList<String>();
		options.add("Kamar tidur");
		options.add("Kamar mandi");
		options.add("Ruang kerja");
		options.add("Ruang belajar");
		options.add("Ruang tamu");
		options.add("Ruang keluarga");
		options.add("Ruang makan");
		options.add("Dapur");
		questionSets.add(new QuestionSet("Fungsi ruangan" , "fungsi" , options));
		
		///Q6
		options = new ArrayList<String>();
		options.add("Sesuai fungsi ruangan");
		options.add("Tidak sesuai fungsi ruangan");
		questionSets.add(new QuestionSet("Nuansa yang ingin diciptakan" , "nuansa" , options));
		
		///Q7
		options = new ArrayList<String>();
		options.add("Natural");
		options.add("Elegan");
		options.add("Lembut dan manis");
		options.add("Damai dan menenangkan");
		options.add("Hangat dan akrab");
		options.add("Ceria dan bersemangat");
		questionSets.add(new QuestionSet("Kesan ruangan yang ingin dimunculkan" , "kesan" , options));

		///Q8
		options = new ArrayList<String>();
		options.add("Ya");
		options.add("Tidak");
		questionSets.add(new QuestionSet("Terdapat jendela pada ruangan" , "keberadaan jendela" , options));

		///Q9
		options = new ArrayList<String>();
		options.add("1");
		options.add("2");
		options.add("3");
		options.add("4");
		options.add("5");
		questionSets.add(new QuestionSet("Jumlah Jendela" , "jumlah jendela" , options));

		///Q10
		options = new ArrayList<String>();
		options.add("Ya");
		options.add("Tidak");
		questionSets.add(new QuestionSet("Terdapat lampu pada ruangan" , "keberadaan lampu" , options));

		///Q11
		options = new ArrayList<String>();
		options.add("Lampu tunggal");
		options.add("Chandelier");
		options.add("Keduanya");
		questionSets.add(new QuestionSet("Jenis lampu yang digunakan" , "jenis lampu" , options));

		///Q12
		options = new ArrayList<String>();
		options.add("1");
		options.add("2");
		options.add("3");
		options.add("4");
		options.add("5");
		options.add("Lebih dari 5");
		questionSets.add(new QuestionSet("Jumlah lampu tunggal" , "jumlah lampu tunggal" , options));

		///Q13
		options = new ArrayList<String>();
		options.add("1");
		options.add("2");
		options.add("Lebih dari 2");
		questionSets.add(new QuestionSet("Jumlah chandelier" , "jumlah chandelier" , options));

		///Q14
		options = new ArrayList<String>();
		options.add("1");
		options.add("2");
		options.add("3");
		options.add("4");
		options.add("5");
		options.add("Lebih dari 5");
		questionSets.add(new QuestionSet("Jumlah lampu tunggal" , "jumlah lampu tunggal" , options));
	}
	
	public QuestionSet getCurrentQuestionSet() {
		return questionSets.get(currentQuestion);
	}
	
	public void advance(int answerIndex) {
		//Save answer
		answerSet.set(currentQuestion, answerIndex);
		
		//Advance question
		if (currentQuestion == 0)
			currentQuestion++;
		else if (currentQuestion == 1)
			currentQuestion++;
		else if (currentQuestion == 2) {
			if (answerIndex == 0)
				currentQuestion = 4;
			else
				currentQuestion++;
		}
		else if (currentQuestion == 3)
			currentQuestion++;
		else if (currentQuestion == 4)
			currentQuestion++;
		else if (currentQuestion == 5)
			currentQuestion++;
		else if (currentQuestion == 6)
		{
			if (answerIndex == 0)
				currentQuestion = 8;
			else
				currentQuestion++;
		}
		else if (currentQuestion == 7)
			currentQuestion++;
		else if (currentQuestion == 8)
		{
			if (answerIndex == 0)
				currentQuestion++;
			else
				currentQuestion=10;
		}
		else if (currentQuestion==9)
			currentQuestion=10;
		else if (currentQuestion == 10)
		{
			if (answerIndex==0)
				currentQuestion++;
			else
				currentQuestion=15;
		}
		else if (currentQuestion == 11)
		{
			if (answerIndex==0)
				currentQuestion=14;
			else if (answerIndex==1)
				currentQuestion=13;
			else
				currentQuestion++;			
		}		
		else if (currentQuestion == 12)
			currentQuestion++;
		else if (currentQuestion == 13)
			currentQuestion=15;
		else if (currentQuestion == 14)
			currentQuestion=15;
	}

	
	public QuestionSet getQuestionSet(int index) {
		if (questionSets.size() > index)
			return questionSets.get(index);
		else
			return null;
	}
	
	public int getCurrentQuestionIdx(){
		return this.currentQuestion;
	}
	
	public static Interviewer getInstance() {
		if (instance == null)
			instance = new Interviewer();
		
		return instance;
	}
}
